package com.bl.service.customer;

import java.util.Random;

import com.bean.Customer;
import com.bl.service.BeanFactory;
import com.bl.util.StringGenerator;
import com.dao.factory.DaoFactory.FactoryType;

/**
 * @author ${user}
 */
public class CustomerFactory
        implements BeanFactory<Customer> {

    private final FactoryType defaultFactoryType;


	public CustomerFactory(FactoryType aDefaultFactoryType) {
		defaultFactoryType = aDefaultFactoryType;
	}


	@Override
    public Customer createBean() {
		Customer customer = null;
        switch (defaultFactoryType) {
			case JDBC:
				customer = new com.dao.jdbc.beans.Customer();
				break;

			default:
				customer = new Customer();
				break;
		}
        return populateCustomer(customer);
    }


    @Override
    public Customer updateBean(Customer aCustomer) {
        return populateCustomer(aCustomer);
    }


    private Customer populateCustomer(Customer aCustomer) {
        StringGenerator stringGenerator = new StringGenerator();
        Random random = new Random();
        int randomInt = random.nextInt(100);
        int age = randomInt;
        aCustomer.setAge(age);
        aCustomer.setFirstName(stringGenerator.generateRandomString(randomInt));
        aCustomer.setLastName(stringGenerator.generateRandomString(randomInt));
        return aCustomer;
    }
}
